package com.fengqianrun.bootframework.controller;

import com.aizuda.easy.security.domain.Rep;
import com.aizuda.easy.security.exp.impl.BasicException;
import com.fengqianrun.bootframework.service.file.FileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;


@RequestMapping("file")
@RestController
@Slf4j
public class FileController {

    @Resource
    private FileService fileService;

    @PostMapping("/toLocal")
    public Rep<String> uploadLocal(@RequestParam("file") MultipartFile file) throws IOException {
        return fileService.uploadLocal(file);
    }

    @PostMapping("/toPublic")
    public Rep<String> uploadPublic(@RequestParam("file") MultipartFile file) throws IOException {
        return fileService.uploadPublic(file);
    }

    @PostMapping("/uploadStrategy")
    public Rep<String> uploadStrategy(@RequestParam("file") MultipartFile file,@RequestParam("path") String path,HttpServletRequest httpServletRequest ) throws IOException, BasicException {
        return fileService.uploadStrategy(file, path, httpServletRequest);
    }

}
